#ifndef DBCLIENT_H
#define DBCLIENT_H

#include "pipe.h"
#include "protocole.h"

#include "dbconfig.h"

#define SRVR_VER    0x12
#define SRVR_VERTXT "DataBaseArchive server v0.1a (STALION)"
#define PERM_NO     0x00
#define PERM_RO     0x01
#define PERM_RW     0x02

class DBClient
{
	public:
		DBClient();
		virtual ~DBClient();

		static void onReadyRead ( Pipe *p, i32 bytes, i32 userdata );
		static void onDataSent ( Pipe *p, i32 bytes, i32 userdata );
		static void onPipeError ( Pipe *p, i32 err_code, i32 userdata );

		void ReciveData ( i32 bytes );
		Pipe *connection;
        i32 active;             // if Client should be erased from quee
	protected:

        i32 permision;          // WR, WO, No permision

		vector<char *> send_buff;
		void AddBuffer ( void *data, i32 len );
		i32 FlushBuffer();
		i32 popBuffer(void *data, i32 len);

        u16 channelNum(u32 device_id, u32 chann_num);       // 7 bit - device, 9 bit channel
        void numChannel( u16 coded, u32 &device_id, u32 &channel_num);
		/// handlers:
		i32 hndlr_welcome   ( dbi_header h );
        i32 hndlr_mdata     ( dbi_header h );



	private:
};

#endif // DBCLIENT_H
